fix(builder): respect output.module with ESM output in the service-worker environment#8752
Conversation
✅ Deploy Preview for modernjs-byted ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: 5fb04b7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 117 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b205e31264
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| chain.output.library({ | ||
| ...(chain.output.get('library') || {}), | ||
| type: 'module', | ||
| }); |
There was a problem hiding this comment.
Drop library names before switching to module output
When a service-worker build has output.module: true and an existing output.library.name from user/environment config, this spread preserves that name while changing the library type to module. Rspack requires module libraries to leave the library name unset, so this turns that previously valid commonjs2 worker configuration into a build-time validation error instead of producing ESM output. Strip or ignore name when selecting module output.
Useful? React with 👍 / 👎.

Problem
The service-worker environment always rewrites the bundler output library type to
commonjs2.When a user enables
output.module, the environment still ends up with a CJS library wrapper, so ESM worker output is not preserved.Fix
Detect service-worker bundler chains that already have module output enabled.
Use
type: 'module'for that case and keepcommonjs2for existing non-module service-worker output.Test
Added a builder unit test for the service-worker module-output branch.
Ran
PUPPETEER_SKIP_DOWNLOAD=1 pnpm install,pnpm --filter @modern-js/builder build, andpnpm --filter @modern-js/builder test.🤖 Generated with Claude Code